home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / test_2.cpp < prev    next >
C/C++ Source or Header  |  1999-01-01  |  5KB  |  170 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  TEST_2.CPP - Hemicube Test Program
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. // NOTE: _NOT_WIN_APP must be globally defined for this
  39. //       program to be successfully compiled
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <iostream.h>
  44. #include <time.h>
  45. #include "error.h"
  46. #include "parse.h"
  47. #include "hemicube.h"
  48.  
  49. // Default entity directory path
  50. static char NoEntityDir[] = "";
  51.  
  52. static HemiCube Hemi;           // Hemicube
  53. static Parse Parser;            // World file parser
  54. static Environ Environment;     // Environment
  55.  
  56. double Calculate( float *, WORD, BOOL );
  57.  
  58. int main( int argc, char **argv )
  59. {
  60.   char *pentdir;        // Entity directory path
  61.   float *ff_array;      // Form factor array
  62.   WORD num_elem;        // Number of elements
  63.  
  64.   // Check hemicube status
  65.   if (Hemi.GetStatus() != TRUE)
  66.   {
  67.     OutOfMemory();
  68.     return 1;
  69.   }
  70.  
  71.   // Get entity directory path (if any)
  72.   if (argc > 2)
  73.     pentdir = argv[2];
  74.   else
  75.     pentdir = NoEntityDir;
  76.  
  77.   // Parse the environment file
  78.   if (Parser.ParseFile(argv[1], pentdir, &Environment) ==
  79.       FALSE)
  80.     return 1;
  81.  
  82.   // Allocate form factor array
  83.   num_elem = Environment.GetNumElem();
  84.   if ((ff_array = new float[num_elem]) == NULL)
  85.   {
  86.     OutOfMemory();
  87.     return 1;
  88.   }
  89.  
  90.   // Seed the random number generator
  91.   srand((unsigned) time(NULL));
  92.  
  93.   // Calculate and display form factors
  94.   (void) Calculate(ff_array, num_elem, TRUE);
  95.  
  96.   // Recalculate form factors and display execution time
  97.   cout << endl << "Resolution = " << FF_ArrayRes << " x "
  98.       << FF_ArrayRes << " cells" << endl;
  99.   cout << "Execution time = "<< Calculate(ff_array,
  100.       num_elem, FALSE) << " seconds";
  101.  
  102.   delete [] ff_array;   // Delete form factor array
  103.  
  104.   return 0;
  105. }
  106.  
  107. // Calculate form factors
  108. double Calculate( float *ff_array, WORD num_elem, BOOL
  109.     ff_flag )
  110. {
  111.   clock_t start, end;   // Execution time variables
  112.   Instance *penv;       // Environment pointer
  113.   Instance *pinst;      // Instance pointer
  114.   Surface3 *psurf;      // Surface pointer
  115.   Patch3 *ppatch;       // Patch pointer
  116.   WORD src_id = 1;      // Source polygon identifier
  117.   WORD rcv_id;          // Receiving polygon identifier
  118.  
  119.   // Get environment pointer
  120.   pinst = penv = Environment.GetInstPtr();
  121.  
  122.   if (ff_flag == FALSE)
  123.   {
  124.     start = clock();    // Start the program timer
  125.   }
  126.  
  127.   // Walk the instance list
  128.   while (pinst != NULL)
  129.   {
  130.     // Walk the surface list
  131.     psurf = pinst->GetSurfPtr();
  132.     while (psurf != NULL)
  133.     {
  134.       // Walk the patch list
  135.       ppatch = psurf->GetPatchPtr();
  136.       while (ppatch != NULL)
  137.       {
  138.         // Calculate patch to element form factors
  139.         Hemi.CalcFormFactors(ppatch, penv, ff_array,
  140.             num_elem);
  141.  
  142.         if (ff_flag == TRUE)
  143.         {
  144.           // Report form factors
  145.           cout << "Patch " << src_id << endl;
  146.           for (rcv_id = 0; rcv_id < num_elem; rcv_id++)
  147.             cout << "  FF(" << src_id << "," << (rcv_id + 1)
  148.                 << ") = " << ff_array[rcv_id] << endl;
  149.         }
  150.  
  151.         src_id++;
  152.         ppatch = ppatch->GetNext();
  153.       }
  154.       psurf = psurf->GetNext();
  155.     }
  156.     pinst = pinst->GetNext();
  157.   }
  158.  
  159.   if (ff_flag == FALSE)
  160.   {
  161.     end = clock();      // Stop the program timer
  162.  
  163.     // Return form factor calculation time
  164.     return (double) (end - start) / CLOCKS_PER_SEC;
  165.   }
  166.   else
  167.     return 0.0;
  168. }
  169.  
  170.